<template>
	<view class="setP">

		<u-navbar :is-back="true" title="设置" :custom-back="BackM" back-text=''>
			<view class="slot-right" style="width: 100%;display: flex;justify-content: flex-end;">
				<!-- <view>
                <image @click="goSettingM" style="width: 1rem;padding: 1rem;" src="../../style/image/my/设 置.png" alt="">
                </view> -->
			</view>
		</u-navbar>


		<view>

			<view @click="goAccountManage" style="display: flex;justify-content: space-between;padding: 1rem;border-bottom: 1px solid #f6f6f6;align-items: center;">
				<view class="set-text">账号管理</view>
				<image style="width: 0.5rem;;height:0.8rem;" src="../../style/image/my/A15.png" alt="">
			</view>

			<view @click="modifypwd" style="display: flex;justify-content: space-between;padding:  1rem;border-bottom: 1px solid #f6f6f6;align-items: center;">
				<view class="set-text">修改登录密码</view>
				<image style="width: 0.5rem;;height:0.8rem;" src="../../style/image/my/A15.png" alt="">
			</view>

			<view style="display: flex;justify-content: space-between;padding:  1rem;border-bottom: 1px solid #f6f6f6;align-items: center;">
				<view class="set-text">推送通知</view>
				<!-- <image  style="width: 0.5rem;" src="../../style/image/my/矩形 16 拷贝 2.png" alt=""> -->

				<!-- <u-switch v-model="status" @change='change' active-color="#02af74" inactive-color="#cccccc" ></u-switch> -->

				<u-switch v-model="status1" @change='change1' active-color="#02af74" inactive-color="#cccccc"></u-switch>
			</view>

		</view>
		<view class="hr"></view>

		<view @click="loginOut" style="display: flex;justify-content: space-between;padding:  1rem;border-bottom: 1px solid #f6f6f6;align-items: center;">

			<view style="display: flex;justify-content: center;align-items: center;">
				<image style="width: 1rem;height:1rem;padding: 0.2rem;" src="../../style/image/my/A23.png" alt="">
					<view class="set-text">退出登录</view>
			</view>
			<image style="width: 0.5rem;height:0.8rem;" src="../../style/image/my/A15.png" alt="">
				<!-- <u-switch v-model="checked" active-color="#2ea27a" inactive-color="#cccccc" ></u-switch> -->
		</view>


	</view>

</template>

<script lang='ts'>
	import {
		Component,
		Prop,
		Vue,
		Watch,
		Emit
	} from "vue-property-decorator";

	// import uNavbar from '@/uview-ui/components/u-navbar/u-navbar.vue'

	import push from "./push.js"

	import uNavbar from "@/uview-ui/components/u-navbar/u-navbar.vue";

	import uSwitch from '../../uview-ui/components/u-switch/u-switch.vue'

	@Component({
		//   @Component  是一个装修器   不可以在下面写语句
		name: "test",
		components: {
			"u-navbar": uNavbar,
			'u-switch': uSwitch,
			// 'u-form-item':uFormItem,
			// 'u-input':uInput
		},
	})

	export default class extends Vue {
		@Prop({
			type: String, // 父组件传递给子组件的数据类型
			required: false, // 是否必填
			default: " ", // 默认值， 如果传入的是 Object，则要 default: ()=>({}) 参数为函数
		})
		msg!: string;

		public status = false;

		public status1 = false

		public clientid: any = ''

		created() {}



		onShow() {
			this.updatePush();
			console.log('updatePush @ onShow');
		}

		mounted() {
			//  console.log('父组件传递的参数:',this.$parent)   //暂时不考虑
			// alert(111)
		}

		updatePush() {
			console.log(push.isOn(), 'push.isOn()值')
			this.status1 = push.isOn();
			console.log(this.status1, '123123this.status	this.status	this.status	this.status')
		}

		pushM() {


			if (this.status == true) {

				(uni as any).subscribePush({
					provider: "unipush",
					success: function(res: any) {
						console.log("success:" + JSON.stringify(res));
					},
				});
				let osname = plus.os.name;

				console.log(osname, "osnameosnameosname");

				if (osname == "Android") {

					(uni as any).onPush({
						provider: "unipush",
						success: function() {
							console.log("监听透传成功");
						},
						callback: function(data: any) {
							console.log("接收到透传数据：" + JSON.stringify(data));
							let obj: any = {};

							plus.push.createMessage(data.data, obj);

						},
					}) as any;

				}
				// 监听在线消息事件
				if (osname == "iOS") {
					plus.push.addEventListener(
						"receive",
						function(msg: any) {
							plus.push.createMessage(msg.content, "LocalMSG", {
								cover: false,
							});
							setTimeout(() => {
								plus.push.clear();
							}, 3000);
						},
						false
					);
				}

				plus.push.addEventListener(
					"click",
					//这里写业务逻辑
					function(data) {
						console.log(data);
					},
					false
				);

				plus.push.addEventListener(
					"receive",
					function(res: any) {
						let options = {
							cover: false
						};
						console.log(res);
						console.log(res.content);
						plus.push.createMessage(res.content, res.payload, options);
					},
					false
				);
			} else {

				console.log('11111111', "关闭")

			}


		}

		modifypwd() {

			uni.navigateTo({
				url: "../../views/Smy/pwd",
			});

		}

		BackM() {

			uni.switchTab({
				url: "../../pages/my/index",
			});

		}



		change1(data: any) {

			console.log(data, '123data', this.status1)

			if (data == true) {
				// #ifdef APP-PLUS
				push.on();
				// #endif
			} else {
				// #ifdef APP-PLUS
				(push as any).off();
				// #endif
			}

		}

		change(status: any) {

			console.log('naniu', this.status)

			this.status = !this.status

			console.log('naniu123', this.status)

			// 				if(this.status==true){
			// // #ifdef APP-PLUS
			// 					push .on();
			// // #endif
			// 				}else{
			// // #ifdef APP-PLUS
			// 					(push as any).off();
			// // #endif
			// 				}


			// console.log(status, "statusstatusstatus");

			// var that=this

			// if (status == true) {

			//    this.pushM()
			//   // plus.push.addEventListener(
			//   //   "click",
			//   //   //这里写业务逻辑
			//   //   function (data) {
			//   //     console.log(data);

			//   //     that.clientid = plus.push.getClientInfo().clientid;

			//   //     console.log(that.clientid,'this.clientidthis.clientid')

			//   //     if (!that.clientid) {
			//   //       //如果获取的cid为空，说明客户端向推送服务器注册还未完成，可以使用setTimeout延时重试。
			//   //       setTimeout(() => {
			//   //         that.clientid = plus.push.getClientInfo().clientid;
			//   //       }, 4000);
			//   //     }

			//   //     plus.push.addEventListener("click", (message) => {
			//   //         pushCallBack();
			//   //     });

			//   //     plus.push.addEventListener("receive", (message) => {
			//   //        pushCallBack();
			//   //     });

			//   //     function pushCallBack() {
			//   //           console.log('推送回调')
			//   //      }

			//   //   },
			//   //   false
			//   // );
			// } else {
			//   console.log("关闭");
			// }



		}

		goAccountManage() {
			console.log("1231312");

			uni.navigateTo({
				url: "../../pages/my/account",
			});
		}

		loginOut() {
			
			console.log("2131312");

			// localStorage.clear()

			uni.navigateTo({
				url: "../login/index",
			});
		}

	}
</script>

<style lang="scss" scoped>
	.u-border-bottom:after {
		border-bottom-width: 0px !important;
	}

	.hr {
		height: 1rem;
		background-color: #f3f5f7;
	}

	.set-text {
		font-size: 0.84rem;
		font-family: PingFang SC;
		font-weight: 400;
		color: #4a4a4a;
	}
</style>
